<?php
require_once 'scripts/jq-config2.php';
// include the jqGrid Class
require_once "scripts/jqGrid.php";
// include the driver class
require_once "scripts/jqGridPdo.php";
// Connection to the server
$conn = new PDO(DB_DSN,DB_USER,DB_PASSWORD);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");
// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT invid, client_id, invdate, amount, tax, total, note FROM invheader';
// Set the table to where you add the data
$grid->table = 'invheader';
// Set output format to json
$grid->dataType = 'json';
// Let the grid create the model
$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('gridEdit.php');
/* */
$grid->setColProperty('invid', array("editable"=>false, "label"=>"ID"));
$grid->setColProperty('invdate', array("editable"=>true, "label"=>"Fecha"));
$grid->setColProperty('client_id', array("editable"=>true, "label"=>"Cliente")); 
$grid->setColProperty('amount', array("editable"=>true, "label"=>"Monto"));
$grid->setColProperty('tax', array("editable"=>true, "label"=>"Impuesto"));
$grid->setColProperty('total', array("editable"=>true, "label"=>"Total"));
$grid->setColProperty('note', array("editable"=>true, "label"=>"Observaciones", "width"=>200)); 
$grid->setColProperty('invdate', 
        array("formatter"=>"date",
            "formatoptions"=>array("srcformat"=>"Y-m-d H:i:s", "newformat"=>"d-m-Y"),
            "editoptions"=>array("dataInit"=>
                "js:function(elm){setTimeout(function(){
                    jQuery(elm).datepicker({dateFormat:'yy-mm-dd'});
                    jQuery('.ui-datepicker').css({'zIndex':'1200','font-size':'75%'});},100);}")
            ));
// Set some grid options
$grid->setGridOptions(array(
	"width"=>600,
	"height"=>'auto',
    "rowNum"=>10,
    "scrollrows"=>true,
    "rowList"=>array(10,20,30),
    "sortname"=>"invid"
));
$grid->navigator= true;
$grid->setNavOptions('navigator', array("excel"=>false,"add"=>false,"edit"=>true,"del"=>false,"view"=>true, "search"=>false));
// Close the dialog after editing
$grid->setNavOptions('edit',array("height"=>'auto',"dataheight"=>'auto',"closeAfterEdit"=>true));
$grid->setNavOptions('add',array("height"=>150,"dataheight"=>'auto',"closeAfterEdit"=>true));

// Enjoy

$grid->renderGrid('#grid','#pager',true, null, null,  true, true);
$conn = null;
?>
